import os
from dataclasses import dataclass

from recruit_bot.core.exceptions import ConfigParseError


def get_str_env(key: str) -> str:
    value = os.getenv(key)
    if not value:
        raise ConfigParseError(f'{key} is not set')
    return value


@dataclass
class Settings:
    token: str
    redis: str


@dataclass
class APIConfig:
    schema: str
    host: str
    port: int


def load_bot_config() -> Settings:
    return Settings(
        token=get_str_env('BOT_TOKEN'),
        redis=get_str_env('REDIS_DSN')
    )


def load_api_config() -> APIConfig:
    return APIConfig(
        schema=get_str_env('SCHEMA'),
        host=get_str_env('HOST'),
        port=int(get_str_env('PORT'))
    )
